(require 'server)
(unless (server-running-p)
  (server-start))

(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))

(setq inhibit-startup-screen t)

;; Increase garbage collection cache.
(setq gc-cons-threshold 50000000)

;; Remap to minimize the chance of closing by mistake.
(defvar my-kill-emacs-binding "C-x C-'")
(global-set-key (kbd my-kill-emacs-binding) 'save-buffers-kill-emacs)
;; Map C-x C-x to do nothing but warn that the mapping has changed
(defun warn-mapping-changed ()
  (interactive)
  (warn (concat "The kill emacs command has been remapped to " my-kill-emacs-binding)))
(global-set-key (kbd "C-x C-c") 'warn-mapping-changed)

(add-to-list 'load-path "~/.emacs.d/vendor/")
(add-to-list 'load-path "~/.emacs.d/site-lisp/")
(add-to-list 'load-path "~/.emacs.d/init.d/")

;; Load private stuff if present (private.el is ignored by git)
;; customization will be saved here.
(setq custom-file "~/.emacs.d/private.el")
(load custom-file t)
(require 'package.cfg)

;; Keep the path settings of the remote account.
(use-package tramp
  :config
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path))

(when
    (string-equal system-type "gnu/linux")
  (progn
    ;; Ensure that the executable path is OK.
    (package-install-if-absent 'exec-path-from-shell)
    (use-package exec-path-from-shell
      :init
      (setq exec-path-from-shell-arguments (list "-l"))
      (exec-path-from-shell-initialize))))

(add-hook 'text-mode-hook 'text-mode-hook-identify)

(add-to-list 'safe-local-variable-values '(TeX-master . "main"))

;; Case-insensitive search
(setq case-fold-search t)

(setq compilation-scroll-output t)

(setq current-language-environment "UTF-8")
(setq default-input-method "utf-8")
(prefer-coding-system 'utf-8)
(when (display-graphic-p)
  (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))

(use-package saveplace
  :init
  (setq-default save-place t)
  (setq save-place-file "~/.emacs.d/saved-places"))

(use-package dired
  :config
  ;; Don't spawn a new buffer for every directory I visit.
  (put 'dired-find-alternate-file 'disabled nil)
  (define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file))

(package-install-if-absent 'smartscan)
(use-package smartscan
  :init
  (global-smartscan-mode 1))

(use-package appearance.cfg)
(use-package gud.cfg)
(use-package buffer.cfg)

(use-package popwin.cfg)
(use-package speedbar.cfg)
(use-package autocomplete.cfg)
(use-package helm.cfg)
(use-package project.cfg)
(use-package parens.cfg)

(package-install-if-absent 'yasnippet)
(use-package yasnippet
  :config
  (yas-reload-all)
  :diminish yas-minor-mode)

(package-install-if-absent 'flycheck)
(use-package flycheck)

(use-package lisp-mode
  :init
  (add-hook 'emacs-lisp-mode-hook 'yas-minor-mode)
  (add-hook 'emacs-lisp-mode-hook 'flycheck-mode))

(use-package vcs.cfg)
(use-package javascript.cfg)
(use-package typescript.cfg)
(use-package rst.cfg)
(use-package python.cfg)
(use-package cc.cfg)
(use-package org-mode.cfg)
(use-package latex.cfg)
(use-package ansible.cfg)

(use-package tdd) ;; Vendored.
